package com.cn.wanxi.servlet;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.NewsModel;
import com.cn.wanxi.service.ICompanyService;
import com.cn.wanxi.service.NavService;
import com.cn.wanxi.service.NewsService;
import com.cn.wanxi.service.impl.CompanyServiceImpl;
import com.cn.wanxi.service.impl.NavServiceImpl;
import com.cn.wanxi.service.impl.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ICompanyService iCompanyService = new CompanyServiceImpl();
//        数据来源于dao层（第二阶段）
//        数据来源于记事本（第三阶段）
//        java的特征  继承，封装，多态
//        多态：以前别人写好的代码不用管，因为可能会出错，现在需要堆以前的功能进行扩展
//        接口（继承）：子类是对父类进行功能扩展
        CompanyModel companyModel = iCompanyService.getCompanyModel();
        req.setAttribute("companyModel", companyModel);


//        導航
        NavService navService = new NavServiceImpl();
        List<NavModel> navModelList = navService.getNavModelList();
        req.setAttribute("navModelList", navModelList);

//        新闻

        NewsService newsService = new NewsServiceImpl();
        List<NewsModel> newsModelList = newsService.getNewsModelListForHomePage();
        req.setAttribute("newsModelList", newsModelList);
        req.getRequestDispatcher("/jsp/home.jsp").forward(req, resp);
    }
}
